//
//  WXPChooseSMSVerificWayView.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/26.
//
//

#import "WXPChooseSMSVerificWayView.h"

@interface WXPChooseSMSVerificWayView ()

@end

@implementation WXPChooseSMSVerificWayView

#pragma mark - lazy
- (UIView *)viewBack{
    if (_viewBack == nil) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.width = SCREEN_WIDTH-2*LEFT_MARDIN;
    }
    return _viewBack;
}
- (UIButton *)btnClose{
    if (_btnClose == nil) {
        _btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnClose.tag = 1;
        [_btnClose addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_btnClose setImage:[UIImage imageNamed:@"icon-login-close"] forState:UIControlStateNormal];
        _btnClose.widthHeight = XY(24+2*LEFT_MARDIN, 24+2*LEFT_MARDIN);
    }
    return _btnClose;
}
- (UILabel *)labelContent{
    if (_labelContent == nil) {
        _labelContent = [UILabel new];
        _labelContent.textColor = COLOR_BLACK;
        _labelContent.fontNum = 18;
        _labelContent.textAlignment = NSTextAlignmentLeft;
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 3;
    }
    return _labelContent;
}
-(UIButton *)btnVoice{
    if (_btnVoice == nil) {
        _btnVoice = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnVoice.tag = 2;
        [_btnVoice addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnVoice.backgroundColor = COLOR_PRIMARY;
        _btnVoice.widthHeight = XY(self.viewBack.width-30-30, BUTTON_HEIGHT);
        [GlobalMethod setRoundView:_btnVoice color:[UIColor clearColor] numRound:_btnVoice.height/2 width:0];
        
        UIImageView * image = [UIImageView new];
        image.widthHeight = XY(Ratio(16), Ratio(16));
        [_btnVoice addSubview:image];
        image.image = [UIImage imageNamed:@"iocn_login-audio"];
        image.leftCenterY = XY(LEFT_MARDIN, _btnVoice.height/2);
        
        UILabel * title = [UILabel new];
        title.font = [UIFont systemFontOfSize:12];
        title.textColor = COLOR_BLACK;
        title.numberOfLines = 0;
        title.lineSpace = 2;
        [title fitTitle:@"Solicitar el código de verificación de voz" variable:_btnVoice.width-LEFT_MARDIN-image.right-8];
        [_btnVoice addSubview:title];
        _btnVoice.height = MAX(title.height+12*2, _btnVoice.height);
        [GlobalMethod setRoundView:_btnSms color:[UIColor clearColor] numRound:_btnVoice.height/2 width:0];
        image.centerY = _btnVoice.height/2;
        title.leftCenterY = XY(image.right+8, _btnVoice.height/2);
    }
    return _btnVoice;
}
-(UIButton *)btnSms{
    if (_btnSms == nil) {
        _btnSms = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnSms.tag = 3;
        [_btnSms addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnSms.backgroundColor = COLOR_LINE;
        _btnSms.widthHeight = XY(self.btnVoice.width, self.btnVoice.height);
        
        UIImageView * image = [UIImageView new];
        image.widthHeight = XY(Ratio(16), Ratio(16));
        [_btnSms addSubview:image];
        image.image = [UIImage imageNamed:@"icon-login-SMS"];
        image.leftCenterY = XY(LEFT_MARDIN, _btnSms.height/2);
        
        UILabel * title = [UILabel new];
        title.font = [UIFont systemFontOfSize:12];
        title.numberOfLines = 0;
        title.lineSpace = 2;
        title.textColor = COLOR_BLACK;
        [title fitTitle:@"Solicitar el código de verificación por SMS" variable:_btnSms.width-LEFT_MARDIN-image.right-8];
        [_btnSms addSubview:title];
        _btnSms.height = MAX(title.height+12*2, _btnSms.height);
        [GlobalMethod setRoundView:_btnSms color:[UIColor clearColor] numRound:_btnSms.height/2 width:0];
        image.centerY = _btnSms.height/2;
        title.leftCenterY = XY(image.right+8, _btnSms.height/2);
    }
    return _btnSms;
}


#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, SCREEN_HEIGHT);
        self.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.4];
        [self addSubView];
    }
    return self;
}

//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.btnClose];
    [self.viewBack addSubview:self.labelContent];
    [self.viewBack addSubview:self.btnVoice];
    [self.viewBack addSubview:self.btnSms];
    [self resetView];
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    switch (sender.tag) {
        case 1:
        {
            [self removeFromSuperview];
        }
            break;
        case 2:
        {
            // 语音验证
            if(self.blockVoiceClick){
                self.blockVoiceClick();
            }
        }
            break;
        case 3:
        {
            // 短信验证
            if(self.blockSmsClick){
                self.blockSmsClick();
            }
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 刷新view
- (void)resetView{
    self.btnClose.rightTop = XY(self.viewBack.width, 0);
    
    [self.labelContent fitTitle:@"En caso de no haber recibido el código de verificación, haga clic para solicitarlo" variable:self.viewBack.width-2*(30)];
    self.labelContent.centerXTop = XY(self.viewBack.width/2, (50));
    
    self.btnVoice.centerXTop = XY(self.viewBack.width/2, self.labelContent.bottom+33);
    
    self.btnSms.centerXTop = XY(self.viewBack.width/2, self.btnVoice.bottom+20);
    
    self.viewBack.height = self.btnSms.bottom+self.labelContent.top;
    [GlobalMethod setRoundView:self.viewBack color:[UIColor clearColor] numRound:16 width:0];
    self.viewBack.centerXCenterY = XY(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
}


@end
